/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package misc;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import org.w3c.dom.Element;
import sun.security.krb5.internal.PAEncTSEnc;


/**
 *
 * @author javierms
 */
public class ObjectGridWizard4 extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    //caixa de texto com tamanho especificado
    
    
    JTextField rowCount;
    JTextField colCount;
    
    JComboBox assoCombo;
    JLabel assLab;
    
    JLabel rowCountLab;
    JLabel colCountLab;
    
    JScrollPane paneContent;
    JTable table;
    
    JButton generateB;
    JButton okB;
    JButton CancelB;
    
    
    private Element objectDiagram;
    
    JLabel l;
    
    Container pane, cp1, cp2, cp3;
    JPanel p,p1,p2, pBottom;
    
    JComboBox combo;
    TableCellEditor editor;
    
   
    public ObjectGridWizard4() {
      //  initComponents();
        
    }
    
    public ObjectGridWizard4(Element one_diagram){
        
        objectDiagram = one_diagram;
        
        rowCount = new JTextField(3);
        colCount = new JTextField(3);
        
        rowCountLab = new JLabel("Rows:");
        colCountLab = new JLabel("Columns:");
        
        generateB = new JButton("Generate");
        generateB.setPreferredSize(new Dimension(90, 30));
        generateB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
         
                //rowCountTable = Integer.parseInt(rowCount.getText());
               // colCountTable = Integer.parseInt(colCount.getText());
                
                final TableCellEditor editors[][] = new TableCellEditor[4][4];
                JTable temp = fillTable();
               
                table = new JTable(temp.getModel()){

            public TableCellEditor getCellEditor(int row, int column)
            {
                int modelColumn = convertColumnIndexToModel(column);

                if (modelColumn != 0)                    
                    return editors[row][column];
                else
                   return super.getCellEditor(row, column);
            }
            
         
            
        
    };
        combo = new JComboBox();
        combo.addItem("aaaa1");
        combo.addItem("aaaa2");
        combo.addItem("aaaa3");
        combo.addItem("aaaa4");
        
        
        
        paneContent = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        
        editor = new DefaultCellEditor(combo);
        table.setCellEditor(editor);
        //table.setdefa null, editor);
        
        
        //paneContent.setViewport((JViewport)table);
        paneContent.setPreferredSize(new Dimension(470, 350));
                
        cp2 = new Container();
        cp2.setLayout(new FlowLayout(FlowLayout.LEFT));
        cp2.add(paneContent, BorderLayout.CENTER);
        
        pBottom = new JPanel();
        pBottom.setLayout(new FlowLayout(FlowLayout.RIGHT));
        pBottom.add(okB);
        pBottom.add(CancelB);
        
        cp3 = new Container();
        cp3.setLayout(new FlowLayout(FlowLayout.RIGHT));
        cp3.add(pBottom, BorderLayout.CENTER);
        
        pane.add(cp2);
        pane.add(cp3, BorderLayout.CENTER);
        


        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(495, 535);
        setVisible(true);
                
              
            }
        });
        
        
        
                
                /*
                addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
               
               setTitle("Push Generate buton");
               l.setText("Push Generate buton");
                //paneContent.repaint();
                //cp2.repaint();
                //pane.repaint();
               //
               
               int row_Count = 5, col_Count = 5;
         final TableCellEditor editors[][] = new TableCellEditor[row_Count][col_Count];
        
        String colNames[] = new String[col_Count];
        colNames[0] = "Objects1:";
        
        for(int i = 1; i < col_Count; i ++){
            colNames[i] = "Objects1";
        }
        
        Object [][] data = new Object[row_Count][col_Count];
        DefaultTableModel model = new DefaultTableModel(data, colNames);
  
        table.setModel(model);
       */
            
               
               //

               
       // paneContent = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
       // paneContent.setPreferredSize(new Dimension(470, 350));
        
        assoCombo = new JComboBox();
        assLab = new JLabel("Associations:");
        
        //table = fillTable();
        //paneContent = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        //paneContent.setPreferredSize(new Dimension(470, 350));
        
        okB = new JButton("Ok");
        okB.setPreferredSize(new Dimension(80, 30));
        okB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // get label of selected radiobutton
               setTitle("Ok");
            }
        });
               
    
        CancelB = new JButton("Cancel");
        CancelB.setPreferredSize(new Dimension(80, 30));
        CancelB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // get label of selected radiobutton
               dispose();
            }
        });
        
        pane = this.getContentPane(); //captura o painel do JFrame
        pane.setLayout(new FlowLayout(FlowLayout.LEFT)); //define o layout

        p = new JPanel();
        p.setLayout(new FlowLayout(FlowLayout.LEFT));
        p.add(assLab);
        p.add(assoCombo);
       
        
        
        p1 = new JPanel();
        p1.setLayout(new FlowLayout(FlowLayout.LEFT));
        p1.add(rowCountLab);
        p1.add(rowCount);
        p1.add(colCountLab);
        p1.add(colCount);
        p1.add(generateB);
       
        cp1 = new Container();
        cp1.setLayout(new GridLayout(2, 1));
        cp1.add(p);
        cp1.add(p1);

        /*
       
        cp2 = new Container();
        cp2.setLayout(new FlowLayout(FlowLayout.LEFT));
        cp2.add(paneContent, BorderLayout.CENTER);
        
        l = new JLabel("aaaaaaaaaaaaaaaaaaa");
        cp2.add(l);
        
               
        pBottom = new JPanel();
        pBottom.setLayout(new FlowLayout(FlowLayout.RIGHT));
        pBottom.add(okB);
        pBottom.add(CancelB);
        
        cp3 = new Container();
        cp3.setLayout(new FlowLayout(FlowLayout.RIGHT));
        cp3.add(pBottom, BorderLayout.CENTER);
 */
        pane.add(cp1);
       // pane.add(cp2);
       // pane.add(cp3, BorderLayout.CENTER);
        


        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(495, 120);
        this.setVisible(true);
    
    }
    
   private JTable fillTable(){
        int row_Count = 5, col_Count = 5;
         final TableCellEditor editors[][] = new TableCellEditor[row_Count][col_Count];
        
        String colNames[] = new String[col_Count];
        colNames[0] = "Objects:";
        
        for(int i = 1; i < col_Count; i ++){
            colNames[i] = "Objects";
        }
        
        Object [][] data = new Object[row_Count][col_Count];
        DefaultTableModel model = new DefaultTableModel(data, colNames);
  
        JTable table = new JTable(model){

            public TableCellEditor getCellEditor(int row, int column)
            {
                int modelColumn = convertColumnIndexToModel(column);

                if (modelColumn != 0)                    
                    return editors[row][column];
                else
                   return super.getCellEditor(row, column);
            }
   };
    return table;
    }  
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ObjectGridWizard4(null).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
